<?php
error_reporting(0);
require('blacklist.php');
function cookie_checkuserinlist($value) {
  $listss = [];
  if (!isset($_COOKIE) || empty($_COOKIE)) {
      return [false,-1]; 
  }
  foreach ($_COOKIE as $key => $cookieValue) {
      if (strpos($key, 'user_key_') === 0) {
          $listss[] = $cookieValue;
          if ($cookieValue === $value) {
              return [true, $listss];
          }
      }
  }
  return [false, $listss];
}
$ip = $_SERVER['REMOTE_ADDR'];
if (in_array($ip, $blacklist)) {
  echo "<script>location = '/ban.php';</script>";
  } 
if (isset($_COOKIE['user_key'])) {
  $currentUser = $_COOKIE['user_key'];
  $gettis_bolaos = cookie_checkuserinlist($currentUser);
  if($gettis_bolaos[0]){
    $currentUser = $gettis_bolaos[1];
  }else{
  $currentUser = [-1];
  }
}else{
  $currentUser = [-1];
}
echo "<script>var serverUserKey =".  $currentUser .";</script>";
?>
<script>
    var sessionStorageUser = sessionStorage.getItem('user');
    if (sessionStorageUser === null || sessionStorageUser === '') {
        location = '/ban.php';
    }
    if(!JSON.parse(serverUserKey).includes(sessionStorageUser)){
        location = '/ban.php';
    }
</script>